
package com.gopay.common.rcs.service.antiphish.manager.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.gopay.common.constants.rcs.AntiPhishEditNatureEnum;
import com.gopay.common.rcs.manager.antiphish.RcsAntiPhishEditLogManager;
import com.gopay.common.rcs.service.antiphish.manager.RcsAntiPhishEditLogService;
import com.gopay.common.rcs.vo.AntiphsihingEditLogVo;
import com.gopay.common.util.StringTools;

/**
 *	@author lwk
 *	@2013年8月14日下午3:00:58
 *	@RcsAntiPhishEditLogServiceImpl.java
 */
@Service("rcsAntiPhishEditLogService")
public class RcsAntiPhishEditLogServiceImpl implements RcsAntiPhishEditLogService {
	
    @Resource(name="rcsAntiPhishEditLogManager")
    RcsAntiPhishEditLogManager rcsAntiPhishEditLogManager;
    
    @Override
    public List<AntiphsihingEditLogVo> findAntiPhishEditLog(Map<String, Object> parameterMap, int pageIndex, int pageSize) {
      List<?>  arrayList= rcsAntiPhishEditLogManager.findAntiPhishLog(parameterMap, pageIndex, pageSize);
      List<AntiphsihingEditLogVo> list=buildVoList(arrayList);
      return list;
    }

	private List<AntiphsihingEditLogVo> buildVoList(List<?> arrayList) {
		List<AntiphsihingEditLogVo> list = new ArrayList<AntiphsihingEditLogVo>();
		for (int i = 0, size = null == arrayList ? 0 : arrayList.size(); i < size; i++) {
			Object[] strArr = (Object[]) arrayList.get(i);
			AntiphsihingEditLogVo vo = new AntiphsihingEditLogVo();
            if(strArr[6]!=null && strArr[7]!=null){
                String changeContent = getChangeContent((String) strArr[6], (String) strArr[7]);
                vo.setChangeContent(changeContent);
            }
			vo.setCreatedTs((String) strArr[0]);
			vo.setCustName((String) strArr[1]);
			vo.setOperConfType(((String) strArr[2]).equals("01") ? "全局设置" : "单商户设置");
			vo.setValBeforeEdit(StringTools.checkNulltoString(strArr[3]));
			vo.setValAfterEdit(StringTools.checkNulltoString(strArr[4]));
			vo.setOperName(StringTools.checkNulltoString(strArr[5]));
			list.add(vo);
		}
		return list;
	}
    /**
     * 根据修改限制 和原规则类型 判断变更内容
     * @param editNature 修改限制
     * @param originalType 原规则类型
     * @return 变更内容
     */
    private String getChangeContent(String editNature,String originalType){
        String changeContent=null;
          if(editNature.equals(AntiPhishEditNatureEnum.ANTI_PHISH_TYPE.value)&&originalType.equals("01")){
              changeContent="域名校验";
          }else if(editNature.equals(AntiPhishEditNatureEnum.ANTI_PHISH_TYPE.value)&&originalType.equals("02")){
              changeContent="域名模糊匹配";
          }else if(editNature.equals(AntiPhishEditNatureEnum.LEGAL_VALUE.value)&&(originalType.equals("02")||originalType.equals("01"))){
              changeContent="域名列表";
          }else if(editNature.equals(AntiPhishEditNatureEnum.DISJUNCTOR.value)&&originalType.equals("03")){
              changeContent="时间戳校验";
          }else if(editNature.equals(AntiPhishEditNatureEnum.LEGAL_VALUE.value)&&originalType.equals("03")){
              changeContent="时间戳差值";
          }else if(editNature.equals(AntiPhishEditNatureEnum.ILLEGAL_REQ_DICISION.value)&&originalType.equals("04")){
              changeContent="订单IP校验";
          }else if(editNature.equals(AntiPhishEditNatureEnum.GATEWAY_CHANNEL.value)&&originalType.equals("05")){
              changeContent="验证码输入";
          }else if(editNature.equals(AntiPhishEditNatureEnum.LEGAL_VALUE.value)&&originalType.equals("05")){
              changeContent="商户LOGO变更";
          }else if(editNature.equals(AntiPhishEditNatureEnum.LEGAL_VALUE.value)&&originalType.equals("06")){
              changeContent="付款到银行IP备案";
          }
        return changeContent;
    }

    @Override
    public int getCount(Map<String, Object> parameterMap) {
        return rcsAntiPhishEditLogManager.getCount(parameterMap);
    }

}

